﻿using System.ComponentModel.Composition;
using System.Text.RegularExpressions;
using TPTecnicas.MessageProcessor.Business;
using TPTecnicas.MessageProcessor.Common;

namespace TPTecnicas.MessageProcessor.Actions
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    [Export(typeof(IAction))]
    [ExportMetadata("Name", "GenerarRespuestaTicket")]
    public class GenerarRespuestaTicket : Action
    {
        [ImportingConstructor]
        public GenerarRespuestaTicket([Import("context")]IUniversityContext context)
            : base(context)
        {
        }

        public override void Execute(IMessage message)
        {
            var regex = new Regex(@"^\[CONSULTA-(?<tipoConsulta>\w+)\] (?<tema>.*)$");
            var match = regex.Match(message.Subject);
            var tipoConsulta = match.Groups["tipoConsulta"].Value;
            var mailCopia = "";
            if (tipoConsulta == "PUBLICA")
            {
                mailCopia = "mailmateriagrupo";
            }
            else if (tipoConsulta == "PRIVATE")
            {
                mailCopia = "";
            }

            //TODO REVISAR, saqué mailcopia porque no entendía ya que no había implementación NAG
            Context.MessagesToSend.Add(new Message() { Subject = message.Subject, Body = message.Body, Destinatary = message.Destinatary });
        }
    }
}
